package cn.itsource.hbc.pet.service.impl;

import cn.itsource.basic.service.impl.BaseServiceImpl;
import cn.itsource.hbc.pet.domain.Pet;
import cn.itsource.hbc.pet.domain.PetDetail;
import cn.itsource.hbc.pet.mapper.PetDetailMapper;
import cn.itsource.hbc.pet.mapper.PetMapper;
import cn.itsource.hbc.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class PetServiceImpl extends BaseServiceImpl<Pet> implements IPetService {

    @Autowired
    private PetMapper petMapper;

    @Autowired
    private PetDetailMapper petDetailMapper;


    @Override
    @Transactional
    public void save(Pet pet) {
        System.err.println(pet);
        super.save(pet);
        // 获取pet对象中的detail对象

        PetDetail detail = pet.getDetail();
        // 关联两张表
        detail.setPet_id(pet.getId());
        // 保存一把
        petDetailMapper.save(detail);
    }

    @Override
    public void onSale(Long[] ids) {
        petMapper.onSale(ids);
    }

    @Override
    public void offSale(Long[] ids) {
        petMapper.offSale(ids);
    }

    @Override
    public Pet loadByIdOfFront(Long id) {
        return petMapper.loadByIdOfFront(id);
    }
}
